local xiongyis = fk.CreateSkill {

  name = "joy__xiongyis",

  tags = { Skill.Limited, },

}



xiongyis:addEffect(fk.AskForPeaches, {
  name = "joy__xiongyis",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.AskForPeaches},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xiongyis.name) and player.dying and player:usedSkillTimes(xiongyis.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = "#xiongyis1-invoke:::"..tostring(math.min(3, player.maxHp))
    if table.find(player.room.alive_players, function(p)
      return p.general == "joy__xushi" or p.deputyGeneral == "joy__xushi" end)
    then
      prompt = "#xiongyis2-invoke"
    end
    if player.room:askForSkillInvoke(player, xiongyis.name, nil, prompt) then
      event:setCostData(self, prompt)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = tonumber(string.sub(event:getCostData(self), 10, 10))
    if n == 1 then
      local maxHp = player.maxHp
      room:recover({
        who = player,
        num = math.min(3, maxHp) - player.hp,
        recoverBy = player,
        skillName = xiongyis.name
      })
      room:changeHero(player, "joy__xushi", false, false, true, false)
    else
      room:recover({
        who = player,
        num = 1 - player.hp,
        recoverBy = player,
        skillName = xiongyis.name
      })
      room:handleAddLoseSkills(player, "joy__hunzi", nil, true, false)
    end
  end,
})

return xiongyis